<template>
  <view class="container">
    <uni-forms ref="form" :modelValue="form" labelWidth="120px" labelPosition="top">
      <view class="hidden-title">停车方案</view>
      <view class="background-white">
        <uni-forms-item name="carPark" class="acceptance" required>
          <view slot="label">
            <view class="flex align-center">
              <view class="mr-20">是否停车</view>
              <view class="acceptance-list">
                <view
                  class="acceptance-item"
                  v-for="(item, index) in acceptanceList"
                  :key="item.code"
                  :class="{ active: form.carPark == item.dictValue }"
                  @click="form.carPark = item.dictValue"
                >
                  <image
                    class="icon-style"
                    v-show="form.carPark != item.dictValue"
                    src="/static/images/work/dbd//selected_no.png"
                    mode="aspectFill"
                  ></image>
                  <image
                    class="icon-style"
                    v-show="form.carPark == item.dictValue"
                    src="/static/images/work/dbd//selected_yes.png"
                    mode="aspectFill"
                  ></image>
                  <text class="content">{{ item.dictLabel }}</text>
                </view>
              </view>
            </view>
          </view>
        </uni-forms-item>
        <uni-forms-item name="parkTime" v-if="form.carPark === 1">
          <uni-datetime-picker v-model.trim="form.parkTime" hide-second :end="form.parkTime" type="datetime">
            <cu-cell title="停车时间" required link placeholder="选择时间" :description="form.parkTime"></cu-cell>
          </uni-datetime-picker>
        </uni-forms-item>
      </view>
    </uni-forms>
    <view class="submit-group">
      <button class="u-button" :ripple="true" @click="submit">提交</button>
    </view>
  </view>
</template>

<script>
import CuCellGroup from '@/components/cu-cell/cu-cell-group.vue'
import CuSelect from '@/components/cu-select/cu-select.vue'
import { park } from '@/api/repair/repair.js'

export default {
  components: {
    CuCellGroup
  },
  data() {
    return {
      acceptanceList: [
        { dictLabel: '是', dictValue: 1 },
        { dictLabel: '否', dictValue: 2 }
      ],
      id: '',
      procTaskId: '',
      form: {
        carPark: '',
        parkTime: ''
      },
      rules: {
        carPark: {
          rules: [
            {
              required: true,
              errorMessage: '是否停车不能为空'
            }
          ]
        },
        parkTime: {
          rules: [
            {
              required: true,
              errorMessage: '停车时间不能为空'
            }
          ]
        }
      }
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  onLoad(option) {
    if (!option.data) return
    let data = JSON.parse(option.data)
    this.id = data.id
    this.procTaskId = data.procTaskId
  },
  methods: {
    submit() {
      this.$refs.form.validate().then((res) => {
        let data = {
          id: this.id,
          procTaskId: this.procTaskId,
          deviceExamineWorkflowEntity: {
            examineId: this.id,
            opinionType: 'PASS'
          },
          parkInfo: this.form
        }
        park(data).then((res) => {
          this.$modal.showToast('处理成功')
          uni.$emit('refresh')
          uni.navigateBack()
        })
      })
    }
  }
}
</script>

<style lang="scss">
.container {
  margin-bottom: 200rpx;

  .background-white {
    background-color: #fff;
    padding: 20rpx 30rpx;
    box-sizing: border-box;

    .uni-forms-item__label {
      color: #333;
      font-size: 30rpx;
    }

    .bor-btm {
      display: flex;
      border-bottom: 1px solid #d5d7e3;
    }

    .photo {
      display: flex;
      justify-content: space-between;

      image {
        width: 214rpx;
        height: 214rpx;
      }
    }

    .text {
      padding-bottom: 20rpx;
      padding-top: 4rpx;
      color: #333;

      text {
        color: #666;
      }
    }
  }
}

.hidden-title {
  background: #f5f5f5;
  padding: 20rpx;
  color: #999;
}

.bor-top {
  border-top: 20rpx solid #f5f5f5;
}

.blue {
  color: #88b4c4;
}

.icon-style {
  width: 52rpx;
  height: 42rpx;
  padding-right: 10rpx;
}
.input {
  display: inline-block;
  width: 100%;
  background-color: #f5f5f5;
  padding: 20rpx;
  font-size: 28rpx;
  border-radius: 10rpx;
  height: 60rpx;
}
.acceptance {
  margin-bottom: 10rpx;
}
.acceptance-list {
  display: flex;

  .acceptance-item {
    display: flex;
    align-items: center;
    margin-left: 20rpx;
    color: #333;

    .icon-style {
      width: 50rpx;
      height: 40rpx;
      margin-right: 10rpx;
    }

    .content {
      flex: 1;
    }
  }
}
</style>
